//
//  TagSelectCollectionCell.m
//  XV
//
//  Created by apple on 04/06/2019.
//  Copyright © 2019 XR. All rights reserved.
//

#import "TagSelectCollectionCell.h"

@interface TagSelectCollectionCell()

@property (nonatomic, strong) UIButton* titleButton;

@end


@implementation TagSelectCollectionCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}

- (void)setup
{
    [self.contentView addSubview:self.titleButton];
    
    [_titleButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
}


-(void)setName:(NSString *)name
{
    _name = name;
    
    [_titleButton setTitle:_name forState:UIControlStateNormal];
    [_titleButton setTitle:_name forState:UIControlStateSelected];
}

-(void)setIsSelected:(BOOL)isSelected
{
    _isSelected = isSelected;
    _titleButton.selected = _isSelected;
    if (_isSelected)
    {
        [_titleButton setBackgroundColor:ColorHex(0xFF506D)];
    }
    else
    {
        [_titleButton setBackgroundColor:[UIColor clearColor]];
    }
}


- (UIButton *)titleButton {
    if (_titleButton == nil) {
        _titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_titleButton setTitleColor:ColorHex(0x999999) forState:UIControlStateNormal];
        [_titleButton setTitleColor:ColorHex(0xffffff) forState:UIControlStateSelected];
        _titleButton.titleLabel.font = [UIFont systemFontOfSize:15];
        _titleButton.layer.cornerRadius = 15;
        _titleButton.layer.borderWidth = 1.0f;
        _titleButton.layer.borderColor = ColorHex(0xE1E1E1).CGColor;
        _titleButton.userInteractionEnabled = NO;
    }
    return _titleButton;
}

@end
